home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-01-22 | 1.9 KB | 85 lines | [TEXT/PJMM] |
- program Main;
-
- uses
- Profiler;
-
- var
- crcTable: array[0..255] of longint;
- crcCC1, crcCC2: longint;
- x: integer;
-
- procedure DoCrcBitCalc;
- const
- hiBitMask = $08000;
- polyCCITT = $01021;
- polyCRC16 = $0A001;
- var
- loop, i: integer;
- tempdata, crcXor: longint;
- begin
- crcCC2 := 0;
- for i := 0 to 255 do
- begin
- tempData := i;
- crcCC2 := BitXor(BitShift(tempData, 8), crcCC2);
- for loop := 1 to 8 do
- begin
- crcXor := BitAnd(crcCC2, hiBitMask);
- if BitTst(@crcXor, 16) then
- crcCC2 := BitXor(BitShift(crcCC2, 1), polyCCITT)
- else
- crcCC2 := BitShift(crcCC2, 1);
- end;
- crcCC2 := BitAnd(crcCC2, 65535);
- end;
- end;
-
-
- procedure DoTableTest;
- var
- i: integer;
- tempData, crc: longint;
- begin
- crcCC1 := 0;
- for i := 0 to 255 do
- begin
- tempData := i;
- crcCC1 := BitAnd(BitXor(BitShift(crcCC1, 8), crcTable[BitAnd(BitXor(BitShift(crcCC1, -8), tempData), 255)]), 65535);
- end;
- end;
-
-
- procedure MakeCRCTable;
- const
- hiBitMask = $08000;
- polyCCITT = $01021; {CRC-CCITT polynomial}
- polyCRC16 = $0A001; {CRC16 polynomial}
- var
- crcCC, crcXor, i, tableCounter: longint;
- loop: byte;
- begin
- for tableCounter := 0 to 255 do
- begin
- crcCC := 0; {must be set to zero}
- crcCC := BitXor(BitShift(tableCounter, 8), crcCC);
- for loop := 1 to 8 do
- begin
- crcXor := BitAnd(crcCC, hiBitMask); {get the high bit value}
- if BitTst(@crcXor, 16) then {is the bit set}
- crcCC := BitXor(BitShift(crcCC, 1), polyCCITT) {then shift and subtract the poly}
- else
- crcCC := BitShift(crcCC, 1); {then just shift for the next test}
- end;
- crcTable[tableCounter] := BitAnd(crcCC, 65535); {save it in the table}
- end;
- end;
-
- begin
- MakeCRCTable;
- for x := 0 to 9 do
- begin
- DoCrcBitCalc;
- DoTableTest;
- end;
- DumpProfileToFile('CRCTestFile');
- end.